package com.pactera.madp.cp.controller.oms.agent;

import com.pactera.madp.common.core.util.R;
import com.pactera.madp.cp.api.model.authorization.OfficialAccountPreCodeResponse;
import com.pactera.madp.cp.api.vo.wechat.WechatAuthorizerListVO;
import com.pactera.madp.cp.api.vo.wechat.WechatMarketingVO;
import com.pactera.madp.cp.service.WechatComponentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @author yushen.qi
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wx")
@Api(value = "wx-mp", tags = "微信公众号授权管理")
public class MpCalBkController {

    @Resource
    private WechatComponentService wechatComponentService;

    @GetMapping("/authorization")
    @ApiOperation(value ="网页授权")
    public R<String> getAuthorization() throws UnsupportedEncodingException {
     //  wechatComponentService.getUserAuthorization();
        return R.ok();
    }

    @GetMapping("/access")
    @ApiOperation(value = "获取公众号accessToken")
    public R<OfficialAccountPreCodeResponse> getAccessToken(String appId, String code){
        return R.ok(wechatComponentService.getUserAuthorizationAccessToken(appId,code));
    }

    @GetMapping("/page")
    @ApiOperation(value = "获取/同步公众号素材列表")
    public R<WechatMarketingVO> getMarketingList(@RequestParam(value = "appId")String appId,Integer classification, String type, Integer offset, Integer count){
        //wechatComponentService.getMarketingList(appId, classification,type, offset, count);
       return R.ok();
    }

    @GetMapping("/index")
    @ApiOperation(value = "获取授权公众号列表")
    public R<List<WechatAuthorizerListVO>> getAuthorizerList(Integer offset, Integer count){
       // wechatComponentService.getAuthorizerList(offset, count)
       return R.ok();
    }

    @GetMapping("/info")
    @ApiOperation(value = "获取选择素材的详细信息")
    public R<String> getAuthorizerList(String appId,String mediaId){
        return R.ok(wechatComponentService.materialInfo(appId, mediaId));
    }

    @GetMapping("/change")
    @ApiOperation(value = "选择展示的公众号")
    public R changeState(@RequestParam(value = "appIds")String appIds){
       wechatComponentService.changeState(appIds);
       return R.ok();
    }

   @GetMapping("/status")
   @ApiOperation(value = "展示的公众号")
    public R<List<WechatAuthorizerListVO>> getListByStatus(){
       return R.ok(wechatComponentService.getAuthorizerListByState());
   }

}
